<template>
  <div class="complex-search">
    <div class="search-outside" @mouseenter="outsideEnter" @mouseleave="outsideLeave">
      <i class="el-icon-tickets" style="color:#fff"/> 所有分类
    </div>
    <!-- 下方list弹窗框 -->
    <div v-if="innerShow" class="search-inner" @mouseleave="innerLeave">
      <ul class="list-navs">
        <li
          v-for="(item, index) in innerList"
          :key="index"
          :class="{active:id === item.id}"
          class="list-nav"
          @mouseenter="innerEnter(item)"
        >
          <span :class="{active:id === item.id}" class="nav-title">{{ item.name }}</span>
          <span :class="{active:id === item.id}" class="nav-right">></span>
        </li>
      </ul>
    </div>
    <!-- 右边弹出框 -->
    <div v-if="currentList" class="inner-right" @mouseenter="rightEnter" @mouseleave="rightLeave">
      <ul class="classify-wrap">
        <li v-for="(item,index) in currentList" :key="index" class="classify-item">
          <span class="classify-title">{{ item.title }}</span>
          <div class="content-wrap">
            <div class="content-header">
              <div
                v-for="(currentType,currentTypeIndex) in item.typeOptions"
                :key="currentTypeIndex"
                :class="{typeactive:item.type === currentType.value}"
                class="content-type"
                @click="type = item.type = currentType.value"
              >
                {{ currentType.label }}
                <i class="el-icon-arrow-right"/>
              </div>
            </div>
            <!-- 各种课程 -->
            <div class="content-main">
              <span
                v-for="(content,contentIndex) in item[item.type]"
                :key="contentIndex"
                :title="content.label"
                :value="content.value"
                class="content-item"
                @click="handleClickClass(content,contentIndex)"
              >{{ content.label }}</span>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { unbuyPackageBus } from './eventBus'
import { getAssetsCategory } from '@/api/subject/digitalAssets' // 数据接口
import { getTenantId } from '@/utils/auth'
export default {
  data() {
    return {
      innerShow: false,
      rightShow: false,
      id: '',
      innerList: [],
      rightList: {}
    }
  },
  computed: {
    currentList() {
      return this.rightList[this.id]
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      getAssetsCategory(getTenantId()).then(res => {
        this.innerList = res.data.innerList
        this.rightList = res.data.rightMap
      })
    },
    handleClickClass(content, contentIndex) {
      unbuyPackageBus.$emit('handleFilter', { categoryId: content.value })
    },
    outsideEnter() {
      this.innerShow = true
      if (this.innerTimer) {
        clearTimeout(this.innerTimer)
      }
      this.id = ''
    },
    outsideLeave() {
      const _this = this
      _this.outTimer = setTimeout(() => {
        _this.innerShow = false
      }, 50)
    },
    innerEnter(item) {
      this.id = item.id
      clearTimeout(this.outTimer)
      if (this.rightTimer) {
        clearTimeout(this.rightTimer)
      }
      console.log(this.id)
    },
    innerLeave() {
      const _this = this
      _this.innerTimer = setTimeout(() => {
        _this.innerShow = false
        _this.id = ''
      }, 50)
    },
    rightEnter() {
      clearTimeout(this.innerTimer)
    },
    rightLeave() {
      const _this = this
      _this.rightTimer = setTimeout(() => {
        _this.innerShow = false
        _this.id = ''
      }, 50)
    }
  }
}
</script>

<style lang="scss">
.complex-search {
  display: block;
  float: left;
  .search-outside {
    width: 130px;
    height: 45px;
    font-size: 14px;
    line-height: 45px;
    margin-top: 10px;
    margin-left: 20px;
    padding: 0 10px;
    background-color: #409eff;
    color: #fff;
    border-radius: 1px;
    cursor: pointer;
    .el-icon-tickets {
      margin-left: 10px;
      margin-right: 8px;
      font-size: 16px;
    }
  }
  .search-inner {
    position: absolute;
    left: 40px;
    width: 130px;
    background-color: #409eff;
    z-index: 21;
    box-shadow: 0 2px 20px #767676;
    .list-navs {
      width: 100%;
      margin: 0;
      padding: 0;
      list-style: none;
      .active {
        background-color: #fff;
        color: #409eff;
        border-color: #409eff;
      }
      .list-nav {
        height: 40px;
        line-height: 40px;
        padding: 0 20px;
        border-top: 1px solid rgba(245, 245, 245, 0.1);
        margin-bottom: 1px;
        cursor: default;
        .active {
          color: #409eff !important;
          border-color: #409eff;
        }
        .nav-title {
          color: #fff;
          font-size: 14px;
        }
        .nav-right {
          color: rgba(255, 255, 255, 0.4);
          font-size: 14px;
          float: right;
          font-weight: 600;
          margin-top: -1px;
        }
      }
    }
  }
  .inner-right {
    position: absolute;
    left: 150px;
    width: 130px;
    width: 1080px;
    height: 492px;
    padding-top: 50px;
    padding-left: 30px;
    padding-bottom: 5px;
    background-color: #fff;
    box-shadow: 0 2px 3px rgba(245,245,245,1);
    z-index: 20;
    overflow: hidden;
    box-shadow: 0 2px 20px #767676;
    .classify-wrap {
      width: 100%;
      padding: 0;
      margin: 0;
      list-style: none;
      .classify-item {
        display: block;
        float: left;
        width: 350px;
        height: 210px;
        line-height: 18px;
        margin-bottom: 30px;
        // background-color:green;
        span.classify-title {
          display: inline-block;
          width: 100%;
          color: #373737;
          border-bottom: 1px solid #eaeaea;
          padding-bottom: 10px;
          margin-bottom: 20px;
        }
        .content-wrap {
          padding-right: 25px;
          .content-header {
            width: 100%;
            height: 30px;
            margin-bottom: 20px;
            .content-type {
              padding: 5px 8px 5px 13px;
              font-size: 12px;
              float: left;
              color: #fff;
              background-color: #333333;
              line-height: 20px;
              margin-right: 10px;
              cursor: pointer;
              .el-icon-arrow-right {
                margin-left: 5px;
                color: #fff;
                transform: rotate(90deg);
                transition: transform 0.2s;
              }
            }
            .typeactive {
              .el-icon-arrow-right {
                transform: rotate(-90deg);
              }
              background-color: #409eff !important;
            }
            div:nth-child(3) {
              margin-right: 0;
            }
          }
          .content-main {
            width: 100%;
            // background: yellow;
            height: 105px;
            padding: 0 12px 0 10px;
            overflow: hidden;
            .content-item {
              display: block;
              float: left;
              margin-right: 18px;
              margin-bottom: 20px;
              width: 52px;
              height: 15px;
              padding: 0;
              font-size: 13px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              cursor: pointer;
            }
            .content-item:hover {
              color: #409eff;
            }
          }
        }
      }
    }
  }
}
</style>
